//
//  RecommendViewController.m
//  iOS-CtrlV
//
//  Created by Wang Li on 12-12-19.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "RecommendViewController.h"
#import "MainTabBarController.h"
@interface RecommendViewController ()

@end

@implementation RecommendViewController

- (id)init
{
    if (self = [super init]) {
        // Custom initialization
        self.m_NowModeType = Mode_Type_RecommendOrNew;
    }
    return self;
}

-(void) dealloc
{
    [_PopToRootBtt release];
    [super dealloc];
}

- (void)viewDidLoad
{
    self.m_RquestURL = [NSString stringWithFormat:@"%@?app=blog&act=recommond&order_by=hot",RequestMainURL];
     [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor colorWithRed:204/255.f green:204/255.f blue:204/255.f alpha:1]];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
	// Do any additional setup after loading the view.
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_LeftNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
        
//        UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
//        tImgView.frame =CGRectMake(0, 44, 320, 5);
//        [self.navigationController.navigationBar addSubview:tImgView];
//        [tImgView release];
    }
    if ([self.navigationController.navigationBar viewWithTag:0x300] == nil) {
        UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
        tImgView.tag =0x300;
        tImgView.frame =CGRectMake(0, 44, 320, 5);
        [self.navigationController.navigationBar addSubview:tImgView];
        [tImgView release];
    }
    if (_PopToRootBtt == nil) {
        _PopToRootBtt =[UIButton buttonWithType:UIButtonTypeCustom];
        _PopToRootBtt.frame =CGRectMake(120, 0, 80, 44);
        [_PopToRootBtt addTarget:self action:@selector(popToRoot) forControlEvents:UIControlEventTouchUpInside];
        [_PopToRootBtt retain];
        [self.navigationController.navigationBar addSubview:_PopToRootBtt];
    }
    _SearchBttBarItem = [UIButton buttonWithType:UIButtonTypeCustom];
    _SearchBttBarItem.frame =CGRectMake(320-44, 0, 44, 44);
    [_SearchBttBarItem setImage:[UIImage imageNamed:@"navsearch.png"] forState:UIControlStateNormal];
    [_SearchBttBarItem addTarget:self action:@selector(startSearchView) forControlEvents:UIControlEventTouchUpInside];
    [_SearchBttBarItem retain];
    [self.navigationController.navigationBar addSubview:_SearchBttBarItem];
    [self firstDataGet];
}


-(void) popToRoot
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_SearchBttBarItem removeFromSuperview];
}

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([_SearchBttBarItem superview] ==nil) {
        [self.navigationController.navigationBar addSubview:_SearchBttBarItem];
    }
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_LeftNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
    }
    
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    [tMainTabBar.m_TabbarCustom removeFromSuperview];
    tMainTabBar.m_TabbarCustom.hidden =NO;
    [self.view addSubview:tMainTabBar.m_TabbarCustom];
}

-(void) startSearchView
{
    _searchStatus = !_searchStatus;
    if (_searchStatus) {
        [self showSearchView];
    }else{
        [self dissSearchView];
    }
}

-(void) AttDissSearch
{
    _searchStatus =NO;
    [self dissSearchView];
}
@end
